package com.xxx.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author: xxx
 * @Date: 2023/1/9 20:03
 * @Description: rabbitmq配置类
 */
@Configuration
public class RabbitMQConfig {

    private static final String QUEUE01="queue_fanout01";
    private static final String QUEUE02="queue_fanout02";
    private static final String EXCHANGE="fanoutExchange";

    /**
     * 1准备队列
     * @return
     */
    @Bean
    public Queue queue(){
        return new Queue("queue",true);
    }

    /**
     * 1准备队列
     * @return
     */
    @Bean
    public Queue queue1(){
        return new Queue(QUEUE01);
    }

    /**
     * 1准备队列
     * @return
     */
    @Bean
    public Queue queue2(){
        return new Queue(QUEUE02);
    }

    /**
     * 1准备交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(EXCHANGE);
    }


    /**
     * 2、队列绑定交换机
     */
    @Bean
    public Binding binding01(){
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }

    /**
     * 2、队列绑定交换机
     */
    @Bean
    public Binding binding02(){
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }


}
